#ifndef __LCD_H__
#define __LCD_H__

#include "stdint.h"

#define TFT_SCK_0 HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_RESET)
#define TFT_SCK_1 HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_SET)

#define TFT_SDA_0 HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_RESET)
#define TFT_SDA_1 HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_SET)

#define TFT_RST_0 HAL_GPIO_WritePin(TFT_RST_GPIO_Port, TFT_RST_Pin, GPIO_PIN_RESET)
#define TFT_RST_1 HAL_GPIO_WritePin(TFT_RST_GPIO_Port, TFT_RST_Pin, GPIO_PIN_SET)

#define TFT_DC_0 HAL_GPIO_WritePin(TFT_DC_GPIO_Port, TFT_DC_Pin, GPIO_PIN_RESET)
#define TFT_DC_1 HAL_GPIO_WritePin(TFT_DC_GPIO_Port, TFT_DC_Pin, GPIO_PIN_SET)

#define TFT_CS_0 HAL_GPIO_WritePin(GPIOB, GPIO_PIN_9, GPIO_PIN_RESET)
#define TFT_CS_1 HAL_GPIO_WritePin(GPIOB, GPIO_PIN_9, GPIO_PIN_SET)

#define TFT_BL_0 HAL_GPIO_WritePin(TFT_BL_GPIO_Port, TFT_BL_Pin, GPIO_PIN_RESET)
#define TFT_BL_1 HAL_GPIO_WritePin(TFT_BL_GPIO_Port, TFT_BL_Pin, GPIO_PIN_SET)

#define DIS_DIR 3 
#define RED 0XF800   // 红色
#define GREEN 0X07E0 // 绿色
#define BLUE 0X001F  // 蓝色
#define WHITE 0XFFFF // 白色
#define BLACK 0X0000 // 黑色

#define PROGMEM 
#define TFT_COLUMN_NUMBER 320
#define TFT_LINE_NUMBER 240
#define TFT_COLUMN_OFFSET 0

void TFT_Clear(unsigned short int back_c);
void TFT_DrawBuf(unsigned char *buf, unsigned short x, unsigned short y, unsigned short w, unsigned short h);
void TFT_Init(void);
void Delay_ms(unsigned int _ms_time);

extern uint16_t  waring_icon[40*40];
extern uint16_t  unit[80*120];
extern uint16_t  number[220*160];
extern uint16_t  log_text[320*80];

void display_waring_icon(void);
void display_unit(void);
void display_number(void);
void display_log_text(void);
void display_log(char C, uint16_t backgorund_color, uint16_t font_color, uint8_t h, uint8_t l);

// 创建tft类
struct tft_dev
{
  uint16_t fontcolor;
  uint8_t textfont, textsize;
  uint16_t buf[1][1];
  void (*init)(void);
  void (*setTextColor)(uint16_t color);
  void (*setFreeFont)(void);
  void (*setTextSize)(uint8_t size);
  void (*drawPixel)(uint16_t x, uint16_t y, uint16_t color);
  void (*drawFastVLine)(uint16_t x, uint16_t y, int h, uint16_t color);
  void (*drawFastHLine)(uint16_t x, uint16_t y, int w, uint16_t color);
  void (*drawBitmap)(uint16_t x, uint16_t y,const uint8_t *bitmap, uint16_t w, uint16_t h, uint16_t color);
  void (*drawLine)(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color);
  void (*drawRect)(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color);
  void (*drawEllipse)(uint16_t x0, uint16_t y0, uint16_t rx, uint16_t ry, uint16_t color);
  void (*fillRect)(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color);
  void (*drawChar)(char c, int32_t x, int32_t y, uint16_t color);
  void (*drawString)(const char *string, int32_t poX, int32_t poY);
  void (*drawNixie)(int x, int y, int w, int pix, uint16_t color, int num, int last_num);
  void (*flash)(void);
};

extern struct tft_dev tft;

#endif
